/*
 * @(#)TestSuiteMap.java
 *
 * Revision:
 * Author                                         Date           
 * --------------------------------------------   ------------   
 *                                                13/12/2011    
 */
package br.edu.ufcg.splab.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import br.edu.ufcg.splab.generator.TestCase;
import br.edu.ufcg.splab.generator.TestSuite;

public class MapTestSuite {
	
	private Map<Integer, TestCase> mapTestSuite;
		
	public MapTestSuite(TestSuite ts){
		setMapTestSuite(ts);		
	}

	/**
	 * Returns the map to which the test cases are mapped.
     * @return The map of the test cases.
	 * if this map contains no mapping for the test case.
	 */
	public Map<Integer, TestCase> getMapTestSuite() {
		return mapTestSuite;
	}

	/**
	 * Replaces the map from these test cases.
	 * @param ts The test suite to be stored in the map.
	 */
	public void setMapTestSuite(TestSuite ts) {
		mapTestSuite = new HashMap<Integer, TestCase>();
		List<TestCase> testCases = ts.getTestSuite();
		int i = 1;
		for(TestCase testCase:testCases){
			mapTestSuite.put(i, testCase);
			i = i + 1;
		}	
	}
	
	/**
	 * Replaces the map of the test cases.
	 * @param mapTestSuite The map to be stored.
	 */
	public void setMapTestSuite(Map<Integer, TestCase> mapTestSuite) {
		this.mapTestSuite = mapTestSuite;
	}

	/**
	 * Returns the key to which the specified test case is mapped,
     * or -1 if this map contains no mapping for the test case.
	 * @param testCase The test case whose associated key is to be returned.
	 * @return The key to which the specified test case is mapped or -1 
	 * if this map contains no mapping for the test case.
	 */
	public int getValueTestCase(TestCase testCase){
		if(mapTestSuite.containsValue(testCase)){
			Set<Entry<Integer, TestCase>> set = mapTestSuite.entrySet();
			for(Entry<Integer, TestCase> entry:set){
				if(entry.getValue().equals(testCase)){
					return entry.getKey();
				}
			}
		};
		return -1;
	}
	
	/**
	 * Returns the test case to which the specified key is mapped,
     * or {@code null} if this map contains no mapping for the key.
	 * @param key The key whose associated test case is to be returned.
	 * @return The test case to which the specified key is mapped, or
     *         {@code null} if this map contains no mapping for the key.
	 */
	public TestCase getTestCase(int key){
		return mapTestSuite.get(key);
	}
	
}
